package com.EAIPClub.userauth.controller;

import com.EAIPClub.userauth.service.LoginService;
import com.EAIPClub.userauth.service.RegisterService;
import com.EAIPClub.userauth.service.TokenService;
import com.api.POJO.UserAuth.Account;
import com.api.POJO.UserAuth.AuthReturnMsg;
import com.api.POJO.UserAuth.RegisterAccount;
import com.api.POJO.UserAuth.RegisterReturnMsg;
import com.api.POJO.UserBaseInfoManager.BaseInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description :用户登录信息管理模块控制层
 * @Author :崔昌赫
 * @Date : 2021/10/15
 */
@RestController
@Slf4j
@CrossOrigin(origins = "*",maxAge = 3600)
public class UserAuthController {
    private LoginService loginService;

    @Autowired
    public void setLoginService(LoginService loginService) {
        this.loginService = loginService;
    }

    private RegisterService registerService;

    @Autowired
    public void setRegisterService(RegisterService registerService) {
        this.registerService = registerService;
    }

    private TokenService tokenService;

    @Autowired
    public void setTokenService(TokenService tokenService) {
        this.tokenService = tokenService;
    }

    @GetMapping("/users/login")
    public AuthReturnMsg login(@RequestBody Account account){
        log.info("{}",account);
        return loginService.login(account);
    }

    @GetMapping("/users/register")
    RegisterReturnMsg registerUserBaseInfo(@RequestBody RegisterAccount registerAccount){
        log.info("{}",registerAccount);
       return registerService.register(registerAccount);
    }

    @GetMapping("/users/login/token/{token}")
    AuthReturnMsg token(@PathVariable String token) {
        log.info("{}",token);
        return tokenService.token(token);
    }


}
